import com.ycf.mapper.UserMapper;
import com.ycf.pojo.User;
import com.ycf.untils.MybatisUnities;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class te {
    @Test
    public void ts() {
        SqlSession sqlSession = MybatisUnities.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> userList = mapper.getUserList();
        for (User user : userList) {
            System.out.println(user);
        }
        sqlSession.close();
    }

    @Test
    public void getUserById() {
        SqlSession sqlSession = MybatisUnities.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        User user = mapper.getUserById(3);
        System.out.println(user);
        sqlSession.close();
    }
    @Test
    public void getUserListByNameLike() {
        SqlSession sqlSession = MybatisUnities.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> userList = mapper.getUserListByNameLike("%i%");
        for (User user : userList) {
            System.out.println(user);
        }
        sqlSession.close();
    }

    @Test
    public void addUser() {
        SqlSession sqlSession = MybatisUnities.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        int resuser = mapper.addUser(new User("te", "123"));
        System.out.println(resuser);

        sqlSession.close();
    }

}
